package Logic;

import java.util.*;

public class PokerGame3 {
    //每一副牌的价值进行排序
    static TreeMap<String,Integer> tree=new TreeMap<>();
    static ArrayList<String> list=new ArrayList<>();

    static{
        String []sign={"♦","♣","♥","♠"};
        String []num={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        for (String n : num) {
            for (String s : sign) {
                list.add(s+n);
            }
        }

        list.add(" 小王");
        list.add(" 大王");

        tree.put("J",11);
        tree.put("Q",12);
        tree.put("K",13);
        tree.put("A",14);
        tree.put("2",15);
        tree.put("小王",16);
        tree.put("大王",17);

    }
    public PokerGame3(){
        Collections.shuffle(list);

        ArrayList<String>lord=new ArrayList<>();

        ArrayList<String>player1=new ArrayList<>();
        ArrayList<String>player2=new ArrayList<>();
        ArrayList<String>player3=new ArrayList<>();

        for (int i = 0; i < list.size(); i++) {
            if(i>=list.size()-3){
                lord.add(list.get(i));
            }
            else {
                if (i % 3 == 0) {
                    player1.add(list.get(i));
                } else if (i % 3 == 1) {
                    player2.add(list.get(i));
                } else {
                    player3.add(list.get(i));
                }
            }

        }
        sort(lord);
        sort(player1);
        sort(player2);
        sort(player3);

        look(player1,"1");
        look(player2,"2");
        look(player3,"3");
        look(lord,"底牌");
    }

    public static void sort(ArrayList<String> list){

        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int i=getValue(o1)-getValue(o2);
                i=i==0? o1.substring(0,1).compareTo(o2.substring(0,1)):i;
                return i;
            }
        });

    }
    public static int getValue(String o1){
        String tmp=o1.substring(1);
        if(tree.containsKey(tmp)){
            return tree.get(tmp);
        }else{
            return Integer.parseInt(tmp);
        }
    }

    public static void look(ArrayList<String> list,String name) {
        System.out.print(name+":");
        for (String s : list) {
            System.out.print(s+" ");
        }
        System.out.println();
    }

}
